/*******************************************************************************
 * Copyright (c) 2016, 2025 Trig Chen.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Trig Chen - initial API and implementation
 *******************************************************************************/
package org.eclipse.chemclipse.msd.converter.supplier.ascii.io;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;

import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.junit.jupiter.api.Test;

public class MassSpectraReaderTest {

	@Test
	public void testRead_01() throws IOException {

		File file = new File("testdata/files/ms01.ascii");
		MassSpectraReader reader = new MassSpectraReader();
		IMassSpectra ms = reader.read(file, null);
		assertEquals(1, ms.size());
		IScanMSD spec = ms.getMassSpectrum(1);
		assertEquals(1250, spec.getRetentionTime());
		assertEquals(32, spec.getRetentionIndex(), 1e-6);
		assertEquals(27, spec.getIons().size());
		assertEquals(4.7814, spec.getIons().get(0).getIon(), 1e-6);
		assertEquals(8.0, spec.getIons().get(0).getAbundance(), 1e-6);
		assertEquals(4.8659, spec.getIons().get(26).getIon(), 1e-6);
		assertEquals(3.0, spec.getIons().get(26).getAbundance(), 1e-6);
	}

	@Test
	public void testRead_02() throws IOException {

		File file = new File("testdata/files/ms02.ascii");
		MassSpectraReader reader = new MassSpectraReader();
		IMassSpectra ms = reader.read(file, null);
		assertEquals(1, ms.size());
		IScanMSD spec = ms.getMassSpectrum(1);
		assertEquals(0, spec.getRetentionTime());
		assertEquals(2.5, spec.getRetentionIndex(), 1e-6);
		assertEquals(3, spec.getIons().size());
		assertEquals(4.7814, spec.getIons().get(0).getIon(), 1e-6);
		assertEquals(8.0, spec.getIons().get(0).getAbundance(), 1e-6);
		assertEquals(4.7944, spec.getIons().get(2).getIon(), 1e-6);
		assertEquals(0.0, spec.getIons().get(2).getAbundance(), 1e-6);
	}
}
